<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form :inline="true" v-model="SearchForm"  @keydown.enter.native.prevent="getDataList()">
      <el-form-item>
        <el-input v-model="SearchForm.susername" placeholder="学生学号或姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column prop="susername" header-align="center" align="center" label="学生学号">
      </el-table-column>
      <el-table-column prop="stuName" header-align="center" align="center" label="学生姓名">
      </el-table-column>
      <el-table-column prop="grade" header-align="center" align="center" label="指导成绩">
      </el-table-column>
      <el-table-column prop="grade1" header-align="center" align="center" label="评阅成绩">
      </el-table-column>
      <el-table-column prop="grade2" header-align="center" align="center" label="答辩成绩">
      </el-table-column>
      <el-table-column prop="average" header-align="center" align="center" label="学生成绩">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </el-card>
</template>

<script>
import servicesApi from '@/services/servicesApi';
import debounce from 'lodash/debounce';
export default {
  data() {
    return {
      SearchForm: {
        susername: ''
      },
      dataList: [
        { 
          susername: '',
          stuName: '',
          grade: '',
          grade1: '',
          grade2: '',
          average: ''
         }
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
    }
  },
  created() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList: debounce(function() {
      this.dataListLoading = true
      let pageInfo = {
        current: this.pageIndex,
        size: this.pageSize,
        name: this.SearchForm.susername
      }
      servicesApi.teagetgradeenterApi(pageInfo).then(res => {
        // console.log(res.data)
        let code =res.data.code
        let data = res.data.data
        if (code===200) {
          this.dataList = data.list
          this.totalPage = data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    }, 1000, { 'leading': true, 'trailing': false }),
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
  }
}
</script>
